package com.base.api.pubg.crawl;

import com.base.api.pubg.IPubgDataTransactionService;
import com.base.api.pubg.enums.PUBG;
import com.base.api.pubg.httpclient.PUBGHttpClient;
import com.base.dao.pubg.JsondataMapper;
import com.base.dao.pubg.LogitemunequipMapper;
import com.base.dao.pubg.LogplayerpositionMapper;
import com.base.utils.RedisServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 统一配置
 *
 * @author: junw
 * @date: 2018/5/22 10:50
 */
@Component
public class DownloadConfig {

    private IPubgDataTransactionService iPubgDataTransactionService;

    private JsondataMapper jsondataMapper;

    private LogitemunequipMapper logitemunequipMapper;

    private LogplayerpositionMapper logplayerpositionMapper;

    private RedisServer redisServer;

    private PUBGHttpClient pubgHttpClient;

    private List<Thread> threadList;

    private int threadCount;

    private boolean close;

    private String[] nameArray;

    @Autowired
    public DownloadConfig(JsondataMapper jsondataMapper, RedisServer redisServer, PUBGHttpClient pubgHttpClient, LogitemunequipMapper logitemunequipMapper, LogplayerpositionMapper logplayerpositionMapper, IPubgDataTransactionService iPubgDataTransactionService) {
        this.jsondataMapper = jsondataMapper;
        this.redisServer = redisServer;
        this.pubgHttpClient = pubgHttpClient;
        this.logitemunequipMapper = logitemunequipMapper;
        this.logplayerpositionMapper = logplayerpositionMapper;
        this.iPubgDataTransactionService = iPubgDataTransactionService;
    }

    /**
     * 初始化配置
     */
    public void init(){
        this.threadCount = 3;
        this.close = false;
        this.nameArray = new String[]{};
    }

    /**
     * 获取当前启动的线程数
     *
     * @return
     */
    public int getCurrentThreadCount(){
        if(threadList != null){
            return threadList.size();
        }else{
            return 0;
        }
    }

    /**
     * 获取等待下载的种子数量
     *
     * @return
     */
    public Long waitingForDownload(){
        if(redisServer != null){
            return redisServer.listSize(PUBG.QUEUE.getDesc()) + redisServer.listSize(PUBG.TEMPQUEUE.getDesc());
        }else{
            return 0L;
        }
    }

    public String[] getNameArray() {
        return nameArray;
    }

    public void setNameArray(String[] nameArray) {
        this.nameArray = nameArray;
    }

    public int getThreadCount() {
        return threadCount;
    }

    public void setThreadCount(int threadCount) {
        this.threadCount = threadCount;
    }

    public JsondataMapper getJsondataMapper() {
        return jsondataMapper;
    }

    public void setJsondataMapper(JsondataMapper jsondataMapper) {
        this.jsondataMapper = jsondataMapper;
    }

    public RedisServer getRedisServer() {
        return redisServer;
    }

    public void setRedisServer(RedisServer redisServer) {
        this.redisServer = redisServer;
    }

    public PUBGHttpClient getPubgHttpClient() {
        return pubgHttpClient;
    }

    public void setPubgHttpClient(PUBGHttpClient pubgHttpClient) {
        this.pubgHttpClient = pubgHttpClient;
    }

    public boolean isClose() {
        return close;
    }

    public void setClose(boolean close) {
        this.close = close;
    }

    public List<Thread> getThreadList() {
        return threadList;
    }

    public void setThreadList(List<Thread> threadList) {
        this.threadList = threadList;
    }

    public LogitemunequipMapper getLogitemunequipMapper() {
        return logitemunequipMapper;
    }

    public void setLogitemunequipMapper(LogitemunequipMapper logitemunequipMapper) {
        this.logitemunequipMapper = logitemunequipMapper;
    }

    public LogplayerpositionMapper getLogplayerpositionMapper() {
        return logplayerpositionMapper;
    }

    public void setLogplayerpositionMapper(LogplayerpositionMapper logplayerpositionMapper) {
        this.logplayerpositionMapper = logplayerpositionMapper;
    }

    public IPubgDataTransactionService getiPubgDataTransactionService() {
        return iPubgDataTransactionService;
    }

    public void setiPubgDataTransactionService(IPubgDataTransactionService iPubgDataTransactionService) {
        this.iPubgDataTransactionService = iPubgDataTransactionService;
    }
}
